<?
$title = "Member registration";
require("required/dbconnect.php");
require("required/share_function.php");
$_SESSION['pid'] = -1;
require("required/header.php");
if (!empty($_SESSION['loginid'])) {
    ?>
    <script type="text/javascript">
        <!--
        window.location = "index.php"
        //-->
    </script>

    <?
}
?>
<script type="text/javascript" src="required/calendarDateInput.js"></script>
<script language="JavaScript" type="text/javascript" src="required/js/goAjax.js"></script>
<script language="javascript">
	
    function checkExist(field,divName,showName) {
        var value = document.getElementById(field).value;
		
        if(value!=""){
            changeContent('required/js/checkExist.php?field='+field+'&value='+value+"&showName="+showName,divName)
        }
    }
	
    function changeState(countryId) {
		
        if(countryId!=""){
            changeContent('required/js/ajax_place.php?country_id='+countryId+'&tag=state','divState')
        }
    }

    function getAreaType(countryId) 
    {
        changeContent('required/js/getAreaType.php?country_id='+countryId,'divAreaType');
				
    }
	
    function formvalidate(frm1)
    {
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if (document.frm1.email.value!="")
        {
            var x = document.frm1.email.value;
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(x)==false)
            { 
                alert('Please enter a valid email address');
                document.frm1.email.focus();
                return false;
            }
        }
        if(document.frm1.password.value=="")
        {
            alert("Please enter password");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.length<6)
        {
            alert("Password length must be more than 6 characters");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.indexOf(" ")>-1)
        {
            alert("No spacing allowed!");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.cpassword.value=="")
        {
            alert("Please re-enter your password");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.password.value!=document.frm1.cpassword.value)
        {
            alert("Password doesn't match, please check");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.verification_code.value=="")
        {
            alert("Please enter the verification code");
            document.frm1.verification_code.focus();
            return false;
        }
		
		
        if(document.frm1.name.value=="")
        {
            alert("Please enter your name");
            document.frm1.name.focus();
            return false;
        }
        if(document.frm1.hpnumber.value=="")
        {
            alert("Please enter your contact number");
            document.frm1.hpnumber.focus();
            return false;
        }
		
		
        return true;
    }
	
</script>

<?
if (!empty($_SESSION['registersubmit'])) {

    $email = $_SESSION['email'];
    $member_type = $_SESSION['member_type'];
    $name = $_SESSION['name'];
    $last_name = $_SESSION['last_name'];
    $sex = $_SESSION['sex'];
    $dob = $_SESSION['dob'];
    $fax = $_SESSION['fax'];
    $hpnumber = $_SESSION['hpnumber'];
    $address1 = $_SESSION['address1'];
    $address2 = $_SESSION['address2'];
    $postcode = $_SESSION['postcode'];
    $country = $_SESSION['country'];
    $city = $_SESSION['city'];
    $state = $_SESSION['state'];
} else {

    $email = "";
    $member_type = "";
    $name = "";
    $last_name = "";
    $sex = "";
    $dob = "";
    $fax = "";
    $hpnumber = "";
    $address1 = "";
    $address2 = "";
    $postcode = "";
    $country = "1";
    $city = "";
    $state = "";
}
?>

<table width="100%" cellpadding="6" cellspacing="0">
    <tr>
        <td class="page_title_bar">
            Registration 

        </td>

    </tr>	
    <tr>
        <td align="center">
            <form action="os_register2.php" method="post" name="frm1" onSubmit="return formvalidate(this)">
                <table width="100%" height="100%">



                    <?
                    if ($module_offline_purchase == 1) {
                        ?>
                        <tr>
                            <td height="20" colspan="3" align="left">Please note that if you have previously purchased and registered at our shop, please click on the button on the right

                                <input type="button" value="Activate My Online Membership" class="button" onclick="window.open('os_activate_membership.php','_self')" />
                            </td>
                        </tr>
                    <? } ?>
                    <tr>
                        <td height="20" colspan="3"><strong>Account</strong></td>
                    </tr>

                    <tr>
                        <td colspan="3"><font color="#FF0000">*</font> indicates mandatory field </td>
                    </tr>
                    <tr valign="top">
                        <td width="500">Email<font color="#FF0000">*</font></td>
                        <td width="3">:</td>
                        <td><input type="text" size="20" maxlength="80" name="email" id="email" onBlur="checkExist('email','divEmail','email'); return false;" value="<?= $email ?>"><br>Please enter a valid email address to receive the activation email
                            <div id="divEmail"></div>
                        </td>
                    </tr>

                    <tr valign="top">
                        <td>Password<font color="#FF0000">*</font></td><td>:</td><td><input type="password" size="20" maxlength="15" name="password" ><br> Password length must be more than 6 characters (case sensitive)</td>
                    </tr>
                    <tr>
                        <td>Confirm password<font color="#FF0000">*</font></td><td>:</td><td><input type="password" size="20" maxlength="15" name="cpassword"></td>
                    </tr>
                   
                    <?
                    if ($module_special_member == 1) {
                        ?>
                        <tr>
                            <td>I would like to register as </td><td>:</td><td>
                                <input type="radio" checked="checked" name="member_type" value="N"/> Normal User
                                <input type="radio"  name="member_type" value="V" /> VIP (RM10 for registration fee)
                            </td>
                        </tr>
                    <? } else { ?>
                        <input type="hidden" name="member_type" value="N"/>
                    <? } ?>
                    <tr>
                        <td height="20" colspan="3"><br><br><strong>Personal Information</strong></td>
                    </tr>
                    <tr>
                        <td>First Name<font color="#FF0000">*</font></td><td>:</td><td><input type="text" size="20" maxlength="50" name="name"  value="<?= $email ?>"></td>
                    </tr>
                    <tr>
                        <td>Last Name<font color="#FF0000">*</font></td><td>:</td><td><input type="text" size="20" maxlength="50" name="last_name"  value="<?= $email ?>"></td>
                    </tr>
                    <?
                    $malechk = "";
                    $femalechk = "";
                    if ($sex == "male") {
                        $malechk = "checked";
                    } elseif ($sex == "female") {
                        $femalechk = "";
                    }
                    ?>
                    <tr>
                        <td>Gender</td><td>:</td><td><input type="radio" name="sex" value="male" checked>Male<input type="radio" name="sex" value="female">Female</td>
                    </tr>
                    <tr>
                        <td>Birth date</td><td>:</td><td>
                            <?
                            if ($dob == "") {
                                ?>
                                <script>DateInput('dob', true, 'YYYY-MM-DD')</script>
                                <?
                            } else {
                                ?>
                                <script>
                                    var go_date="<?= $dob ?>" ;
                                    DateInput('dob', true, 'YYYY-MM-DD',go_date )
                                </script>
                            <? } ?>

                        </td>
                    </tr>
                    <tr>
                        <td height="20" colspan="3"><br><br>	<strong>Contact Information</strong></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td>:</td><td><input type="text" size="40" maxlength="100" name="address1" value="<?= $address1 ?>"></td>
                    </tr>
                    <tr>
                        <td colspan="2"></td><td><input type="text" size="40" maxlength="100" name="address2"  value="<?= $address2 ?>"></td>
                    </tr>
                    <tr>
                        <td>Postcode</td>
                        <td>:</td><td><input type="text" size="20" maxlength="15" name="postcode"  value="<?= $postcode ?>"></td>
                    </tr>
                    <tr>
                        <td>City</td>
                        <td>:</td><td><input type="text" size="20" maxlength="15" name="city" value="<?= $city ?>"></td>
                    </tr>

                    <tr valign="top">
                        <td>Country</td><td>:</td>
                        <td width="1507">

                            <?
                            $get_place = mysql_query("select * from os_country where status=1 order by main_country desc,engname asc");
                            ?>
                            <select name="country" class="text" onChange="getAreaType(this.value)">

                                <?
                                while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                    if ($country == $s['id']) {
                                        $cslt = "selected";
                                    } else {
                                        $cslt = "";
                                    }
                                    ?>
                                    <option value="<?= $s['id'] ?>" <?= $cslt ?> ><?= $s['engname'] ?></option>
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><div id="divAreaType">State</div></td><td>:</td>
                        <td>
                            <div id="divState">
                                <?
                                $get_place = mysql_query("select * from os_state where country_code=$country order by order_id asc");
                                ?>
                                <select name="state" class="text">
                                    <option value="">Please select</option>
                                    <?
                                    while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                        if ($state == $s['id']) {
                                            $cslt = "selected";
                                        } else {
                                            $cslt = "";
                                        }
                                        ?>
                                        <option  value="<?= $s['id'] ?>" <?= $cslt ?>><?= $s['name_eng'] ?></option>
                                        <?
                                    }
                                    ?>
                                </select>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>Contact number<font color="#FF0000">*</font></td><td>:</td><td><input type="text" size="20" maxlength="20" name="hpnumber"  value="<?= $hpnumber ?>"><br></td>
                    </tr>
                    <tr>
                        <td>Fax</td><td>:</td><td><input type="text" size="20" maxlength="20" name="fax" value="<?= $fax ?>"><br></td>
                    </tr>
                    <tr valign="top">
                        <Td>Security Check</Td>
                        <td>:</td>
                        <td>
                            <script>
                                var RecaptchaOptions = {
                                    theme : 'clean'
                                };
                                var RecaptchaOptions = {  
                                    theme : 'custom',  
                                    lang: 'en',  
                                    custom_theme_widget: 'divrecaptcha' //div enclosing widget elements  
                                };  
                            </script>

                            <div id="divrecaptcha" style="display: none;">

                                <div id="controls"><a href="#" onclick="Recaptcha.reload(); ">Get
                                        another Captcha</a> <br />
                                </div>

                                <div id="recaptcha_image"></div>
                                <!--Important-->

                                <p><input type="text" name="recaptcha_response_field"
                                          id="recaptcha_response_field" /><!--Important--> <br />
                                    <span class="recaptcha_only_if_image">Enter the words shown above
                                        separated by space</span>

                            </div>

                            <?
                            require_once('required/recaptchalib.php');

                            echo recaptcha_get_html($captcha_key_public);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center"><input type="submit" value="Submit" class="button" name="btnsubmit">

                            <input type="reset" value="Reset" class="button">
                        </td>
                    </tr>	

                </table>
            </form>
        </td>
    </tr>
</table>

<? require("required/footer.php"); ?>